package bit.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bit.dao.BoardDAO;
import bit.dao.BoardDTO;

public class BoardUpdateAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		int num = Integer.parseInt(req.getParameter("num"));
		String subject = req.getParameter("subject");
		String content = req.getParameter("content");
		
		BoardDTO dto = new BoardDTO();
		dto.setNum(num);
		dto.setSubject(subject);
		dto.setContent(content);
		
		BoardDAO dao = new BoardDAO();
		int cnt = dao.boardUpdate(dto);
		
		ActionForward forward = null;
		if(cnt>0){
			forward = new ActionForward();
			forward.setPath("detail.do?num="+num);
			forward.setRedirect(true);
		}

		return forward;
	}

}
